home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Dev / GNU-SMALLTALK.lha / examples / up.st < prev    next >
Text File  |  1992-02-15  |  3KB  |  122 lines

  1. "Link in pids.c, and install a call to definePidFuncs in initCFuncs  in
  2. mstcint.c.  This will provide access to some process related UNIX system 
  3. calls from within GNU Smalltalk."
  4.  
  5. "======================================================================
  6. |
  7. | Copyright (C) 1990, 1991, 1992 Free Software Foundation, Inc.
  8. | Written by Steve Byrne.
  9. |
  10. | This file is part of GNU Smalltalk.
  11. |
  12. | GNU Smalltalk is free software; you can redistribute it and/or modify it
  13. | under the terms of the GNU General Public License as published by the Free
  14. | Software Foundation; either version 1, or (at your option) any later version.
  15. | GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
  16. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  17. | FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  18. | details.
  19. | You should have received a copy of the GNU General Public License along with
  20. | GNU Smalltalk; see the file LICENSE.  If not, write to the Free Software
  21. | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  
  22. |
  23.  ======================================================================"
  24.  
  25.  
  26.  
  27. Object subclass: #UnixProcess
  28.     instanceVariableNames: 'pid'
  29.     classVariableNames: ''
  30.     poolDictionaries: ''
  31.     category: 'Cool hacking'!
  32.  
  33. Behavior defineCFunc: 'getpid'
  34.          withSelectorArgs: 'getpid'
  35.      forClass: UnixProcess class
  36.      returning: #long
  37.      args: nil.
  38.  
  39. Behavior defineCFunc: 'getpgrp'
  40.          withSelectorArgs: 'getpgrp: pid'
  41.      forClass: UnixProcess
  42.      returning: #long
  43.      args: #(long).
  44. Behavior defineCFunc: 'fork'
  45.          withSelectorArgs: 'fork'
  46.      forClass: UnixProcess class
  47.      returning: #long
  48.      args: nil.
  49.      
  50. Behavior defineCFunc: 'kill'
  51.          withSelectorArgs: 'kill: pid signal: sig'
  52.      forClass: UnixProcess
  53.      returning: #int
  54.      args: #(int int).
  55.  
  56. Behavior defineCFunc: 'vfork'
  57.          withSelectorArgs: 'vfork'
  58.      forClass: UnixProcess class
  59.      returning: #long
  60.      args: nil.
  61.  
  62. Behavior defineCFunc: 'execlp'
  63.          withSelectorArgs: 'execlp: name args: argsArray'
  64.      forClass: UnixProcess class
  65.      returning: #long
  66.      args: #(string variadic)!
  67.  
  68.  
  69. "  defineCFunc('fork', fork);
  70.   defineCFunc('kill', kill);
  71.   defineCFunc('killpg', killpg);
  72.   defineCFunc('getpgrp', getpgrp);
  73.   defineCFunc('setpgrp', setpgrp);
  74.   defineCFunc('getppid', getppid);
  75.   defineCFunc('nice', nice);
  76.   defineCFunc('vfork', vfork);
  77.   defineCFunc('execve', execve);
  78.   defineCFunc('execl', execl);
  79.   defineCFunc('execle', execle);
  80.   defineCFunc('execlp', execlp);
  81.   defineCFunc('execvp', execvp);"
  82.  
  83. !UnixProcess class methodsFor: 'test'!
  84.  
  85. myProc
  86.     ^self new initPid: (self getpid)
  87. !
  88.  
  89. for: aPid
  90.     ^self new initPid: aPid
  91. !!
  92.  
  93.  
  94. !UnixProcess methodsFor: 'accessing'!
  95.  
  96. processGroup
  97.     ^self getpgrp: pid
  98.  
  99. !!
  100.  
  101. !UnixProcess methodsFor: 'private'!
  102.  
  103. initPid: aPid
  104.     pid _ aPid
  105.  
  106. !!
  107.  
  108. | forkPid |
  109.     forkPid _ UnixProcess vfork.
  110.     stdout nextPutAll: 'Hello from process: '.
  111.     forkPid printNl.
  112.     forkPid = 0
  113.         ifTrue: [ ^UnixProcess execlp: 'dectalk'
  114.                            args: #(dectalk I am 'sorry,' I do not know what I am saying 0) ]. 
  115.     forkPid printNl!
  116.  
  117. "| me |
  118. me _ UnixProcess myProc.
  119. me inspect!"
  120.